package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.DietAdvice;
import com.health.teahouse.service.IDietAdviceService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 饮食建议信息Controller
 * 
 * @author yang
 * @date 2024-02-11
 */
@RestController
@RequestMapping("/teahouse/advice")
public class DietAdviceController extends BaseController
{
    @Autowired
    private IDietAdviceService dietAdviceService;

    /**
     * 查询饮食建议信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:list')")
    @GetMapping("/list")
    public TableDataInfo list(DietAdvice dietAdvice)
    {
        startPage();
        List<DietAdvice> list = dietAdviceService.selectDietAdviceList(dietAdvice);
        return getDataTable(list);
    }

    /**
     * 导出饮食建议信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:export')")
    @Log(title = "饮食建议信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DietAdvice dietAdvice)
    {
        List<DietAdvice> list = dietAdviceService.selectDietAdviceList(dietAdvice);
        ExcelUtil<DietAdvice> util = new ExcelUtil<DietAdvice>(DietAdvice.class);
        util.exportExcel(response, list, "饮食建议信息数据");
    }

    /**
     * 获取饮食建议信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:query')")
    @GetMapping(value = "/{adviceId}")
    public AjaxResult getInfo(@PathVariable("adviceId") Long adviceId)
    {
        return success(dietAdviceService.selectDietAdviceByAdviceId(adviceId));
    }

    /**
     * 新增饮食建议信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:add')")
    @Log(title = "饮食建议信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DietAdvice dietAdvice)
    {
        return toAjax(dietAdviceService.insertDietAdvice(dietAdvice));
    }

    /**
     * 修改饮食建议信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:edit')")
    @Log(title = "饮食建议信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DietAdvice dietAdvice)
    {
        return toAjax(dietAdviceService.updateDietAdvice(dietAdvice));
    }

    /**
     * 删除饮食建议信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:advice:remove')")
    @Log(title = "饮食建议信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adviceIds}")
    public AjaxResult remove(@PathVariable Long[] adviceIds)
    {
        return toAjax(dietAdviceService.deleteDietAdviceByAdviceIds(adviceIds));
    }
}
